<?php

class ActiveChecker {

    static private $interval = 3600;
    static private $directory;

    public static function SetDirectory($dir) {
	if(!empty($dir) && is_dir($dir)) {
	    self::$directory = $dir;
	}
    }

    public static function Touch($name) {
	touch(self::$directory . $name);
    }

    public static function Create($name) {
	self::Touch($name);
    }

    public static function Remove($name) {
	$file = self::$directory . $name;
	if(file_exists($file)) {
	    unlink($file);
	}
    }

    public static function Exists($name) {
	if(file_exists(self::$directory . $name)) {
	    return true;
	} else {
	    return false;
	}
    }

    public static function GetList() {
	$list = scandir(self::$directory);
	unset($list[array_search('.svn', $list)]);
	unset($list[array_search('.', $list)]);
	unset($list[array_search('..', $list)]);
	return $list;
    }

    public static function Clean($time = null, $interval = null) {
	if(!is_int($interval)) {
	    $interval = self::$interval;
	}
	if(is_int($time)) {
	    $time = time() - $interval;
	} else {
	    $time = time() - $interval;
	}
	$dh = opendir(self::$directory);
	while(false != ($obj = readdir($dh))) {
	    if($obj == '..' || $obj == '.') {
		continue;
	    }
	    if(filemtime(self::$directory . $obj) <= $time) {
		self::Remove($obj);
	    }
	}
    }
}

?>